package com.lyf.lottery.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lyf.lottery.model.po.OptActivityBlindBox;
import com.lyf.lottery.model.req.OptActivityBlindBoxQuery;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;


/**
 *OptActivityBlindBox mapper接口
 * @author lyf
 **/
@Mapper
public interface OptActivityBlindBoxMapper extends BaseMapper<OptActivityBlindBox> {


	/**
	 * 根据活动id查询已经上架的盲盒总概率
	 * @param activityId
	 * @return
	 */
	@Select("select ifnull(sum(probability),0) from t_opt_activity_blind_box where activity_id = #{activityId} and status =1")
	BigDecimal optActivityBlindBox(@Param("activityId") Integer activityId);

	/**
	 * 减少盲盒的数量和增加中奖数量
	 * @param id
	 * @param currentNum
	 * @return
	 */
	@Update("update t_opt_activity_blind_box set prize_count = prize_count-1,obtain_num = obtain_num +1 where id =#{id} and prize_count=#{currentNum}")
	int decrNumAndIncrObtainNum(@Param("id")Integer id,@Param("currentNum")Integer currentNum);
}
